package cn.com.xf.dao.impl;

import cn.com.xf.dao.TblApiBarDao;
import cn.com.xf.dao.support.XFSqlMapClientDaoSupport;
import cn.com.xf.domain.TblApiBar;
import cn.com.xf.domain.TblCheckReport;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapExecutor;

@Repository
public class TblApiBarDAOImpl extends XFSqlMapClientDaoSupport implements TblApiBarDao {

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public TblApiBarDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public int deleteByPrimaryKey(BigDecimal id) {
		TblApiBar key = new TblApiBar();
		key.setId(id);
		int rows = getSqlMapClientTemplate().delete(
				"TBBAR.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public void insert(TblApiBar record) {
		getSqlMapClientTemplate()
				.insert("TBBAR.ibatorgenerated_insert", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public void insertSelective(TblApiBar record) {
		getSqlMapClientTemplate().insert(
				"TBBAR.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public TblApiBar selectByPrimaryKey(BigDecimal id) {
		TblApiBar key = new TblApiBar();
		key.setId(id);
		TblApiBar record = (TblApiBar) getSqlMapClientTemplate().queryForObject(
				"TBBAR.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public int updateByPrimaryKeySelective(TblApiBar record) {
		int rows = getSqlMapClientTemplate().update(
				"TBBAR.ibatorgenerated_updateByPrimaryKeySelective", record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table TBBAR
	 * @ibatorgenerated  Tue Mar 08 08:51:56 CST 2016
	 */
	public int updateByPrimaryKey(TblApiBar record) {
		int rows = getSqlMapClientTemplate().update(
				"TBBAR.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}

	@Override
	public List<TblApiBar> selectBar(int begin, int pageSize, String orderByField,
			String orderByMode,String siteid,String brand,String deviceid) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("orderByField", orderByField);
		map.put("orderByMode", orderByMode);
		map.put("siteid", siteid);
		map.put("brand", brand);
		map.put("deviceid", deviceid);
		List<TblApiBar> list = getSqlMapClientTemplate().queryForList("TBBAR.selectBars", map);
		return list;
	}

	@Override
	public int selectCount(String siteid,String brand,String deviceid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("siteid", siteid);
		map.put("brand", brand);
		map.put("deviceid", deviceid);
		int count = (Integer)getSqlMapClientTemplate().queryForObject("TBBAR.selectCount", map);
		return count;
	}

	@Override
	public int batchInsert(final List<TblApiBar> list) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				for (TblApiBar s : list) {

					executor.insert("TBBAR.ibatorgenerated_insert", s);

				}
				executor.executeBatch();
				return null;
			}
		});

		return 0;
	}


}